<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class CEmailSender{
	private static $config;
	
	public static function resetConfig(){
		self::$config = new EmailSettingForm();
	}
	
	public static function sendMail($receiver,$title,$message,$config=null){
		if(!isset($config)){			if(!isset(self::$config)){
				self::$config = new EmailSettingForm();
			}
			$config = self::$config;
		}
		if($config->enabledEmail=="0"){
			return "尚未启动邮件发送功能，请联系管理员";
		}
		if($config->enabledMailFun=="1"){			if(mail($receiver, $title, $message)==false){
				return "mail函数方式不能发送邮件，请联系管理员";
			}
		}else{
			$mailer = Yii::createComponent('application.extensions.mailer.EMailer');
			$mailer->Host = $config->smtpServer;
			$mailer->IsSMTP();
			$mailer->IsHTML();
			if($config->checkAuth=="1"){				$mailer->SMTPAuth = true;
				$mailer->Username = $config->name;
				$mailer->Password = $config->passwd;
			}
			$mailer->From = $config->sender;
			$mailer->AddAddress($receiver);
			$mailer->FromName = $config->sender;
			$mailer->CharSet = 'UTF-8';
			$mailer->Subject = $title;
			$mailer->Body = $message;
			if($mailer->Send()==false){
				return "SMTP配置不正确，不能邮件发送错误";
			}
		}
		return true;
	}
}